home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 15939 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.7 KB

  1. Path: news.sprintlink.net!datalytics!usenet
  2. From: Rob Stewart <stew@datalytics.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Arrays or Pointers?
  5. Date: Mon, 08 Apr 1996 16:57:28 -0400
  6. Organization: Datalytics, Inc
  7. Message-ID: <31697DB8.41A7@datalytics.com>
  8. References: <4kbsk3$f07@zeus.tcp.co.uk>
  9. NNTP-Posting-Host: 204.62.224.71
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0 (WinNT; I)
  14.  
  15. David wrote:
  16. > I'm currently on a C++ course and we seem to be using pointers a fair
  17. > bit. On questioning this, was told that pointers where quicker than
  18. > using arrays. In which situations should I be using arrays over
  19. > pointers and vice versa?
  20.  
  21. I had read, many years ago, that on several systems, some tests 
  22. revealed that pointer arithmetic to access an array was faster 
  23. than the equivalent array notation.  As a result of that, and 
  24. since I wasn't terribly comfortable with pointers at that time, 
  25. I committed to using pointers for array accesses as well as more 
  26. "normal" purposes.  The benefit was that I became thoroughly 
  27. familiar with pointers.
  28.  
  29. We recently did some tests with our current compilers: Microsoft 
  30. Visual C++ 2.2 and 4.0, and found that they produced identical 
  31. code.  In fact, the code was no different with or without 
  32. optimizations turned on.  In other words, assuming there was a 
  33. difference years ago, there is likely no difference in today's 
  34. compilers.  You'll need to conduct tests for yourself with your 
  35. compiler to see if it does as well.
  36.  
  37. Since junior programmers are less familiar with pointers than 
  38. arrays, I have reverted to using array syntax again.
  39.  
  40. -- 
  41. Robert Stewart        | My opinions are usually my own.
  42. Datalytics, Inc.    | stew@datalytics.com
  43.